#!/bin/bash
curtime=`date  +"%Y-%m-%d %H:%M:%S" `
echo "当前时间"$curtime

# 获取路径
THIS_DIR=$(cd `dirname $0`; pwd)
echo "路径:   "$THIS_DIR
echo "cd:   "$THIS_DIR"/../"
#cd $THIS_DIR
cd $THIS_DIR"/../"
pwd

# 环境参数
env=$1
if [ ! -n "$env" ]
then
    env=local
fi

xmx=500
if [ "local" == "${env}" ]
then
    echo "local set xmx=2000"
    xmx=2000
fi
echo "xmx:"$xmx

echo "********** step1  env: $env"

echo "********** step2  git pull "
pullFlag=$2
echo "pullFlag: "$pullFlag
if [ "yes" == "$pullFlag" ]
then
    git pull
else
    echo "do not git pull"
fi

# 编译
packageStartTime=`date +%s`
echo "********** step3 package"

# 部署到本地仓库
echo "mvn install ****"
mvn install

# run_docker 的修改点
# source ~/.bash_profile
mvn clean package -P $env -DskipTests=true -Dmaven.source.skip=true -Dsource.skip=true
packageEndTime=`date +%s`
packageTimeCost=$[ packageEndTime - packageStartTime ]
echo "package time cost: "$packageTimeCost"秒"

# 后台运行
# 运行前先停止
echo "kill last app before run"
sh deploy/stop.sh

echo "********** step4 run"
mkdir log
echo "java -Duser.timezone=Asia/Shanghai -jar -Xms100m -Xmx${xmx}m -XX:MetaspaceSize=50M -XX:MaxMetaspaceSize=180M -XX:+PrintGCDetails ruoyi-admin/target/ruoyi-admin.jar --spring.profiles.active=$env"
echo "docker 中不nohup 执行"
java -jar -Duser.timezone=Asia/Shanghai -Xms100m -Xmx${xmx}m -XX:MetaspaceSize=50M -XX:MaxMetaspaceSize=180M -XX:+PrintGCDetails ruoyi-admin/target/ruoyi-admin.jar --spring.profiles.active=$env
